package com.zhibang.sinocare.report.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zhibang.sinocare.common.result.Result;
import com.zhibang.sinocare.common.result.ResultCode;
import com.zhibang.sinocare.common.vo.ZhibiaoVo;
import com.zhibang.sinocare.report.service.ZhibiaoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 接口
 */
@RestController
@CrossOrigin
@RequestMapping("/zhibiao")
@Api(tags = "用户管理")
public class ZhibiaoController {
    @Resource
    private ZhibiaoService zhibiaoServiceImpl;

    @RequestMapping(value = "find",method = RequestMethod.GET)
    @ApiOperation(value = "查询用户",notes = "根据条件分页查询",httpMethod = "GET")
    public Result findZhibiao(@RequestParam(value = "page",defaultValue = "1") Integer page, @RequestParam(value = "limit" ,defaultValue = "5") Integer limit,String searchParams)throws Exception{
        System.out.println("进入find方法");
        System.out.println(searchParams);
        ObjectMapper objectMapper = new ObjectMapper();
        ZhibiaoVo zhibiaoVo = null;
        if (searchParams!=null && !"".equals(searchParams)){
            zhibiaoVo = objectMapper.readValue(searchParams,ZhibiaoVo.class);
        }
        Page page1 = PageHelper.startPage(page,limit);
        List<ZhibiaoVo> zhibiaoVos = zhibiaoServiceImpl.selectZhibiao(zhibiaoVo);

        return Result.ok(ResultCode.SUCCESS,page1.getTotal(),zhibiaoVos);
    }
}
